package com.example.validatestudy.demos.annotation;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Objects;
/**
 * @auther: 王振方
 * @date: 2024 01 31 15 08
 * @description: 测试注解
 */
@Type("cat")
public class TestAnnotation extends Animal{

    public static void main(String[] args) {
        /**
         * Color为自定义的重复注解，Type为普通自定义注解
         */
       Class<TestAnnotation> clazz = TestAnnotation.class;
        Color color = clazz.getAnnotation(Color.class);
        System.out.println("getAnnotation()查询继承注解但不查询重复注解中的数据，\nColor getAnnotation:");
        if(Objects.nonNull(color)){
            System.out.print(color.color());
        }
        Type type = clazz.getAnnotation(Type.class);
        if(Objects.nonNull(type)){
            System.out.println("Type getAnnotation:"+type.value());
        }

        Annotation[]  aArr = clazz.getAnnotations();
        System.out.println("\ngetAnnotations():"+Arrays.toString(aArr));

        Color[] cArr = clazz.getAnnotationsByType(Color.class);
        System.out.println("\ngetAnnotationsByType()查询重复注解及继承注解的数据:"+Arrays.toString(cArr));

        Annotation[]  aArr1 = clazz.getDeclaredAnnotations();
        System.out.println("\ngetDeclaredAnnotations()查询当前类显示声明的注解，不包括继承注解:"+Arrays.toString(aArr1));
    }
}
